﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GLYFrom.TCGL
{
    public partial class CP_SeleDele : Form
    {
        public CP_SeleDele()
        {
            InitializeComponent();
        }

        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {

        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //提示并判断用户的选择
            if (MessageBox.Show("你确定要删除吗？", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                //获取选中行的Id
                int id = Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells["Col_Id"].Value);
                //删除
                int sr = DBHelper.ZSG(string.Format("delete from T_CaiPin where CPId='{0}'",id));
                if (sr>0)
                {
                    MessageBox.Show("删除成功！");
                }
                else
                {
                    MessageBox.Show("删除失败！");
                }
            }
        }

        private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells["Col_Id"].Value);
            TCGL.CP_update from = new CP_update(id);
            from.Show();
        }

        private void TC_SeleDele_Load(object sender, EventArgs e)
        {
            this.dataGridView1.AutoGenerateColumns = false;
            DataTable table = DBHelper.select("select * from T_CaiPin");
            this.dataGridView1.DataSource = table;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string Id = this.text_Id.Text.Trim();
            string Name = this.text_Name.Text.Trim();
            string Class = this.combo_Class.Text.Trim();
            string JiaGe = this.text_JiaGe.Text.Trim();
            string sql = "select * from T_CaiPin where 1=1";
            if (Id.Length>0)
            {
                sql += string.Format("and CPId like '%{0}%'", Id);
            }
            if (Name.Length > 0)
            {
                sql += string.Format("and Name like '%{0}%'", Name);
            }
            if (Class.Length > 0)
            {
                sql += string.Format("and Class like '%{0}%'", Class);
            }
            if (JiaGe.Length > 0)
            {
                sql += string.Format("and JiaGe='{0}'", JiaGe);
            }
            DataTable table = DBHelper.select(sql);
            this.dataGridView1.DataSource = null;
            this.dataGridView1.DataSource = table;
        }

        private void 刷新ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            DataTable table = DBHelper.select("select * from T_CaiPin");
            this.dataGridView1.DataSource = null;
            this.dataGridView1.DataSource = table;
        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void 隐藏已完成订单ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
    }
}
